home *** CD-ROM | disk | FTP | other *** search
/ Night Owl 6 / Night Owl's Shareware - PDSI-006 - Night Owl Corp (1990).iso / 036a / pmfinder.zip / PROCZOO.C < prev    next >
Text File  |  1990-06-12  |  4KB  |  159 lines

  1. /***************************************************************************
  2.  *                                                                         *
  3.  * ZOO Processing Functions                                                *
  4.  *                                                                         *
  5.  **************************************************************************/
  6. #include <stdio.h>
  7. #include <string.h>
  8. #include <io.h>
  9.  
  10. #include "fff.h"
  11. #include "zoo.h"
  12.  
  13. int Match (char *Str, char *Pat);
  14. void PrtVerbose (char *Path, char *Name, DOS_FILE_TIME *Time, DOS_FILE_DATE *Date,
  15.                  long Size);
  16. void ChkPage (void);
  17. int  SearchQ (char *Str);
  18.  
  19. extern char Pattern[66];
  20.  
  21. static int Printed;
  22.  
  23.  void
  24. DoZOO (char *ZOOFileName) {
  25.     extern int Spaced, PageSwt, Lnno;
  26.  
  27.     FILE *ZOOFile;
  28.     unsigned long ZOOPos;
  29.     ZOO_FIXED_TYPE ZOOEntry;
  30.  
  31.     if ( (ZOOFile = fopen(ZOOFileName, "rb")) == NULL) {
  32.         fprintf(stderr, "%s", ZOOFileName);
  33.         perror("");
  34.         }
  35.     if ( !GetZOOHeader(ZOOFile, &ZOOPos) ) {
  36.         Printed = 0;
  37.         while ( !GetNextZOOEntry(ZOOFile, &ZOOPos, &ZOOEntry) )
  38.             DisplayZOOEntry(ZOOFile, ZOOFileName, &ZOOEntry);
  39.         if (Printed) {
  40.             if (PageSwt) ChkPage();
  41.             printf("\n");
  42.             ++Lnno;
  43.             Spaced = 1;
  44.             }
  45.         }
  46.     }
  47.  
  48.  int
  49. GetZOOHeader (FILE *ZOOFile, unsigned long *ZOOPos) {
  50.     ZOO_HEADER_TYPE ZOOHeader;
  51.  
  52.     if ( !fread(&ZOOHeader, sizeof(ZOOHeader), 1, ZOOFile) )
  53.         return(FORMAT_ERROR);
  54.     else if (ZOOHeader.ZOOTag != VALID_ZOO) return(FORMAT_ERROR);
  55.     else *ZOOPos = ZOOHeader.ZOOStart;
  56.     return(0);
  57.     }
  58.  
  59.  int
  60. GetNextZOOEntry (FILE *ZOOFile, unsigned long *ZOOPos, ZOO_FIXED_TYPE *ZOOEntry) {
  61.  
  62.     fseek(ZOOFile, *ZOOPos, SEEK_SET);
  63.     if ( !fread(ZOOEntry, sizeof(*ZOOEntry), 1, ZOOFile) )
  64.         return(FORMAT_ERROR);
  65.     else if (ZOOEntry->ZOOTag != VALID_ZOO) return(FORMAT_ERROR);
  66.     else if ( (*ZOOPos = ZOOEntry->Next) == 0) return(END_OF_FILE);
  67.     return(0);
  68.     }
  69.  
  70.  void
  71. DisplayZOOEntry (FILE *ZOOFile, char *ZOOFileName, ZOO_FIXED_TYPE *ZOOEntry) {
  72.     extern int TotalMatch, VerboseSwt, CaseSwt, Spaced, PageSwt;
  73.     extern char V_Name[14], V_Path[66];
  74.     extern ARC_TYPE ArcType;
  75.     extern int Lnno;
  76.     extern int S[6][3];
  77.  
  78.     char FileName[13];
  79.     char DirectName[65];
  80.     char LongName[65];
  81.     int DelFile;
  82.     ZOO_VARYING_TYPE ZOOVarying;
  83.     unsigned char NamLen;
  84.     unsigned char DirLen;
  85.     char *p;
  86.     int SystemID;
  87.  
  88.     strcpy(FileName, ZOOEntry->FName);
  89.     DelFile = (ZOOEntry->Deleted == 1);
  90.     strcpy(LongName, ""); strcpy(DirectName, "");
  91.     if (DelFile) strcpy(LongName, "  (Deleted");
  92.     else if (ZOOEntry->VarDirLen) {
  93.         if (fread(ZOOVarying, (size_t) ZOOEntry->VarDirLen, (size_t) 1, ZOOFile)) {
  94.             NamLen = ZOOVarying[0];
  95.             DirLen = ZOOVarying[1];
  96.             if ( (long) (NamLen + DirLen + 2) < ZOOEntry->VarDirLen)
  97.                 strncpy( (char *) &SystemID, &ZOOVarying[NamLen + DirLen + 2], 2);
  98.             else SystemID = 4095;
  99.             if ( DirLen || NamLen) {
  100.                 if (NamLen) {
  101.                     strncpy(FileName, (char *) &ZOOVarying[2], NamLen);
  102.                     FileName[NamLen] = '\0';
  103.                     }
  104.                 else strcpy(FileName, ZOOEntry->FName);
  105.                 if (DirLen) {
  106.                     strncpy(DirectName, &ZOOVarying[NamLen+2], DirLen);
  107.                     DirectName[DirLen] = '\0';
  108.                     if (SystemID <= 2)
  109.                         if (DirectName[strlen(DirectName)-1] != '/')
  110.                             strcat(DirectName, "/");
  111.                     }
  112.                 }
  113.             }
  114.         ++S[ArcType][1];
  115.         strcpy(LongName, DirectName); strcat(LongName, FileName);
  116.         if (DirectName[0] != '\0') {
  117.             if (DirectName[strlen(DirectName)-1] != '/')
  118.                 strcat(DirectName, "/");
  119.             }
  120.         strupr(LongName);
  121.         if ( (p = strrchr(LongName, '/')) != NULL) ++p;
  122.         else p = LongName;
  123.         if ( SearchQ(p) ) {
  124.             ++S[ArcType][2];
  125.             ++TotalMatch;
  126.             if (PageSwt) ChkPage();
  127.             if (CaseSwt == ON) {
  128.                 strlwr(DirectName);
  129.                 strlwr(FileName);
  130.                 strlwr(LongName);
  131.                 strlwr(ZOOFileName);
  132.                 }
  133.             if (VerboseSwt) {
  134.                 if (!Printed) {
  135.                     if (!Spaced) {
  136.                         if (PageSwt) ChkPage();
  137.                         printf("\n");
  138.                         ++Lnno;
  139.                         }
  140.                     if (PageSwt) ChkPage();
  141.                     printf("%s\n", ZOOFileName);
  142.                     ++Lnno;
  143.                     Printed = 1;
  144.                     }
  145.                 fputs("* ", stdout);
  146.                 PrtVerbose(DirectName, FileName, &ZOOEntry->Time,
  147.                            &ZOOEntry->Date, ZOOEntry->OrgSize);
  148.                 }
  149.             else {
  150.                 fputs(ZOOFileName, stdout);
  151.                 fputs("--> (", stdout);
  152.                 fputs(LongName, stdout);
  153.                 puts(")");
  154.                 }
  155.             ++Lnno;
  156.             }
  157.         }
  158.     }
  159.